#ifndef MAIN_H
#define MAIN_H
#include <iostream>
#include "mod.h"
#include <string>
#include "mod_list.h"
#include "audio.h"
#include <auto_ptr.h>
#include <boost/filesystem.hpp>
#include <boost/thread.hpp>
#include <boost/algorithm/string.hpp>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int fd;
mod_list list;
template <typename T1,typename T2>
void operatoutmod(string name){
    T1 t1;
    T2 t2;
    mod *mod_p = new mod();
    mod_p->setmodio(in);
    mod_p->com_p = &t1;
    mod_p->get = &t2;
    mod_p->setname(name);
    mod_p->thread_out=new boost::thread(mod_p->com_p->contrl(mod_p->ouput));
    list.add(mod_p);
}

template <typename T1,typename T2>
void operatinmod(string name){
    T1 t1;
    T2 t2;
    mod *mod_p = new mod();
    mod_p->com_p = &t1;
    mod_p->put = &t2;
    mod_p->setname(name);
    mod_p->thread_in=new boost::thread(mod_p->com_p->contrl(mod_p->input));

    list.add(mod_p);
}


template <typename T1,typename T2,typename T3>
void operatmod(string name){
    T1 t1;
    T2 t2;
    T3 t3;
    mod *mod_p = new mod();
    mod_p->com_p = &t1;
    mod_p->get = &t2;
    mod_p->put = &t3;
    mod_p->setname(name);
    mod_p->thread_in=new boost::thread(mod_p->com_p->contrl(mod_p->input));
    mod_p->thread_out=new boost::thread(mod_p->com_p->contrl(mod_p->ouput));
    list.add(mod_p);
}

bool read_maindri(mod_list *mods){
    int id=0;
    read(fd ,&id,sizeof(id));
    if(id==0){
        goto ret;
    }
    if(id>mods->size){
        goto ret;
    }
    mod *m_p = mods->list.at(id);
    *m_p->com_p->open();
ret:
    id=0;
    write(fd,id,sizeof(id));
    return true;
}

void init_driver(){
    fd = open("/dev/webMain",O_RDONLY,644);
}

void init_mod(){

}

#endif // MIAN_H
